Many of the web applications that you use every day rely on a MySQL
database to send and store data. And many of these same applications
are developed in Python. Database engineers can send and
store data from a Python based application to a MySQL database
using a MySQL Python connection. In this video, you'll explore the basics
of this important connection and learn how it works. Over at Little Lemon, the restaurant needs to connect a Python
application with its MySQL database. They need to form this connection so that they can perform basic
MySQL tasks using Python and they also need your
help with these tasks. But first, you need to understand how the
connection between MySQL and Python works. So let's take a few moments to explore
the connection between Python and a MySQL database. A connection is established
between Python and the MySQL database using an application
programming interface or API. An API is also commonly known
as a driver or a client. The API is a written set of programs or
software that acts as a bridge between the front end Python application
and back end MySQL database. This connection can be created using
different APIs like SQLAlchemy. MySQL client and MySQL connector Python. MySQL connector Python is
the most common API and the one that you'll
focus on in this course. A useful way of understanding
the connection between MySQL database and Python is visually. Picture a diagram with a Python
application on one side and a MySQL database on the other. In between these two elements is
the MySQL connector Python API. In a typical interaction
between these elements, the front end python application sends
a connection request to the connector API. The connection request is the Python
application asking for permission to access and retrieve information
from the database using Python. The API forwards the request to
the back end MySQL database. The database accepts the connection. It then sends a message to the Python
application back through the API confirming that the connection
has been established. In other words,
MySQL gives the API permission for the Python application
to access the database. Now the Python application sends
a connection request to the database. Once the connection is established, you can then instantiate an instance
of the cursor from the connector class. And when a cursor object is created, you can then execute SQL queries in
the MySQL database using python. Let's look at Little Lemons
database as an example. Little Lemon need to check what
time a guest is arriving for dinner using their Python application. The date and time data for the guests booking is stored
in the back end database. So the Python application uses
the execute module from the cursor object to carry out the customer's demand. The records are returned through the
cursor object in the form of topples that show the booking slots of each guest. Once the request has been fulfilled,
the cursor object and database connection can be closed. You should now understand and be able to
explain how a connection works between a Python application and a MySQL database. I look forward to teaching you more about
the MySQL Python connection in other videos.